package com.bs.web.controller;

import com.bs.exception.BusinessException;
import com.bs.model.Item;
import com.bs.model.Order;
import com.bs.service.IItemService;
import com.bs.service.IOrderService;
import com.bs.vo.OrderCreateVo;
import com.bs.vo.OrderItemVo;
import com.bs.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 说明：
 *
 * @author 陈晓琪
 */
@RestController
@RequestMapping("order")
@Api(tags = "订单接口")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IItemService itemService;

    @PostMapping("createOrder")
    @ApiOperation("创建订单")
    RestResultVo<Order> createOrder(@RequestBody OrderCreateVo createVo) throws BusinessException {
        Order order = orderService.createOrder(createVo);
        return RestResultVo.ok(order);
    }

    @GetMapping("cancelOrder")
    @ApiOperation("取消订单")
    RestResultVo<String> cancelOrder(String orderId) throws BusinessException {
        orderService.cancelOrder(orderId);
        return RestResultVo.success();
    }

    @GetMapping("payOrder")
    @ApiOperation("支付订单")
    RestResultVo<String> payOrder(String orderId) throws BusinessException {
        orderService.payOrder(orderId);
        return RestResultVo.success();
    }

    @GetMapping("waitingOrder")
    @ApiOperation("完成制作订单")
    RestResultVo<String> waitingOrder(String orderId) throws BusinessException {
        orderService.waitingOrderCode(orderId);
        return RestResultVo.success();
    }

    @GetMapping("codeOrder")
    @ApiOperation("使用取餐码,完成订单")
    RestResultVo<String> codeOrder(String orderId, String orderCode) throws BusinessException {
        orderService.codeOrder(orderId, orderCode);
        return RestResultVo.success();
    }

    @GetMapping("findOrder")
    @ApiOperation("查询订单")
    RestResultVo<Order> findOrder(String orderId) {
        Order order = orderService.getById(orderId);
        return RestResultVo.ok(order);
    }

    @GetMapping("listOrder")
    @ApiOperation("查询全部订单")
    RestResultVo<List<Order>> listOrder() {
        List<Order> orderList = orderService.listOrder();
        return RestResultVo.ok(orderList);
    }

    @GetMapping("listOrderManage")
    @ApiOperation("查询全部订单-管理员")
    RestResultVo<List<Order>> listOrderManage() {
        List<Order> orderList = orderService.listOrderManage();
        return RestResultVo.ok(orderList);
    }

    @GetMapping("listItem")
    @ApiOperation("查询全部商品列表")
    RestResultVo<List<Item>> listItem() {
        return RestResultVo.ok(itemService.list());
    }

}
